home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
14642
/
14642.xpi
/
chrome
/
modules
/
trackers
/
shopping.js
< prev
next >
Wrap
Text File
|
2009-10-21
|
14KB
|
310 lines
/* Copyright 2009, Boomtango.com. All Rights Reserved. */
/* shopping.js
* Responsible for tracking shopping links
*/
var EXPORTED_SYMBOLS = ["shopping"];
var shopping = {
name: "Shopping",
name_plural: "Shopping",
color: "#146EB4",
isInternal: true,
preview: function(doc, node, data){
if(data.preview){
var result = this.json.decode(data.preview);
var hbox, label, spacer, image;
switch(result.type){
case this.AMAZON:
hbox = doc.createElement('hbox');
spacer = doc.createElement('spacer');
spacer.setAttribute('flex', '1');
hbox.appendChild(spacer);
image = doc.createElement('image');
image.setAttribute("src",
"http://ecx.images-amazon.com/images/P/"+result.id +".01.SCMZZZZZZZ.jpg");
hbox.appendChild(image);
spacer = doc.createElement('spacer');
spacer.setAttribute('flex', '1');
hbox.appendChild(spacer);
node.appendChild(hbox);
if(result.price){
hbox = doc.createElement('hbox');
spacer = doc.createElement('spacer');
spacer.setAttribute('flex', '1');
hbox.appendChild(spacer);
label = doc.createElement('label');
label.setAttribute("value", result.price);
label.setAttribute("style", "color: red; font-size: 14px;");
hbox.appendChild(label);
spacer = doc.createElement('spacer');
spacer.setAttribute('flex', '1');
hbox.appendChild(spacer);
node.appendChild(hbox);
}
break;
case this.NEWEGG:
case this.BESTBUY:
case this.WOOT:
case this.SHIRTWOOT:
case this.KIDSWOOT:
case this.WINEWOOT:
case this.SELLOUTWOOT:
case this.BUY:
hbox = doc.createElement('hbox');
spacer = doc.createElement('spacer');
spacer.setAttribute('flex', '1');
hbox.appendChild(spacer);
image = doc.createElement('image');
image.setAttribute("src", result.img);
hbox.appendChild(image);
spacer = doc.createElement('spacer');
spacer.setAttribute('flex', '1');
hbox.appendChild(spacer);
node.appendChild(hbox);
if(result.price){
hbox = doc.createElement('hbox');
spacer = doc.createElement('spacer');
spacer.setAttribute('flex', '1');
hbox.appendChild(spacer);
label = doc.createElement('label');
label.setAttribute("value", result.price);
label.setAttribute("style", "color: red; font-size: 14px;");
hbox.appendChild(label);
spacer = doc.createElement('spacer');
spacer.setAttribute('flex', '1');
hbox.appendChild(spacer);
node.appendChild(hbox);
}
break;
}
}
},
onLoadTracks: function(url, doc){
if(!doc){
return [];
}
var result = [];
var match = this.pattern.exec(url);
if(match){
var obj = {};
var title = "";
var redirect_url = null;
switch(match[1]){
case this.AMAZON:
var asina = /\/([A-Z0-9]{10})($|\/)/.exec(url);
if(asina){
obj.id = asina[1];
obj.type = match[1];
var a = doc.getElementsByClassName('priceLarge');
if(a.length){
obj.price = a[0].textContent;
}
var el = doc.getElementById("btAsinTitle");
if(el){
var pricetxt = obj.price ? " (" + obj.price + ")" : "";
var name = el.textContent;
var namelength = obj.price ? 32 : 40;
if(name.length > namelength){
name = name.substring(0,namelength) + "...";
}
title = "Amazon: " + name + pricetxt;
} else {
title = doc.title;
}
redirect_url = "http://www.amazon.com/gp/product/" + obj.id + "?ie=UTF8&tag=boomtango-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=" + obj.id;
} else {
return [];
}
break;
case this.NEWEGG:
if(url.substring(0, this.NEWEGGURL.length) == this.NEWEGGURL){
var a = /[\?&]Item=([^]*)/.exec(url);
if(a){
obj.id = a[1];
obj.type = match[1];
var a = doc.getElementsByClassName('zmp');
if(a.length){
obj.price = this.trim(a[0].textContent);
}
var el = doc.getElementById("pclaImagePreview");
if(el){
obj.img = el.src;
}
a = doc.getElementsByTagName('h1');
if(a.length){
var pricetxt = obj.price ? " (" + obj.price + ")" : "";
var name = this.trim(a[0].textContent);
var namelength = obj.price ? 32 : 40;
if(name.length > namelength){
name = name.substring(0,namelength) + "...";
}
title = "NewEgg: " + name + pricetxt;
} else {
title = doc.title;
}
redirect_url = "http://www.kqzyfj.com/click-3669670-10440897?url=" + encodeURIComponent(url) + "&cjsku=" + obj.id;
} else {
return [];
}
} else {
return [];
}
break;
case this.BUY:
if(url.substring(0, this.BUYURL.length) == this.BUYURL){
obj.type = match[1];
var el = doc.getElementById("productPricing");
if(el){
if(el.firstChild &&
el.firstChild.firstChild &&
el.firstChild.firstChild.lastChild &&
el.firstChild.firstChild.lastChild.lastChild
){
el = el.firstChild.firstChild.lastChild;
if(el.childNodes.length < 2){
el = el.previousSibling;
}
obj.price = this.trim(el.lastChild.textContent);
}
var el = doc.getElementById("PROD_mainImg");
if(el){
obj.img = el.src;
}
var pricetxt = obj.price ? " (" + obj.price + ")" : "";
var name = doc.title.substring(0, doc.title.length - 10);
var namelength = obj.price ? 32 : 40;
if(name.length > namelength){
name = name.substring(0,namelength) + "...";
}
title = "Buy.com: " + name + pricetxt;
} else {
return [];
}
} else {
return [];
}
break;
case this.WOOT:
case this.KIDSWOOT:
case this.WINEWOOT:
case this.SHIRTWOOT:
case this.SELLOUTWOOT:
if(url == this.WOOTURL ||
url == ("http://" + this.KIDSWOOT + "/") ||
url == ("http://" + this.WINEWOOT + "/") ||
url == ("http://" + this.SHIRTWOOT + "/") ||
url == ("http://" + this.SELLOUTWOOT + "/") ||
url.substring(0,this.SELLOUTURL.length) == this.SELLOUTURL){
obj.type = match[1];
var el = doc.getElementsByClassName("productDescription");
if(el.length){
var el2 = el[0].getElementsByTagName("h2");
var name;
if(el2.length){
name = this.trim(el2[0].textContent);
el2 = el[0].getElementsByClassName("amount");
if(el2.length){
obj.price = "$" + this.trim(el2[0].textContent);
}
} else {
name = "Woot.com";
}
var el2 = doc.getElementsByClassName("photo");
if(el2.length){
obj.img = el2[0].src;
}
var pricetxt = obj.price ? " (" + obj.price + ")" : "";
var namelength = obj.price ? 32 : 40;
if(name.length > namelength){
name = name.substring(0,namelength) + "...";
}
title = "Woot: " + name + pricetxt;
} else {
return [];
}
} else {
return [];
}
break;
case this.BESTBUY:
if(url.substring(0, this.BESTBUYURL.length) == this.BESTBUYURL){
obj.type = match[1];
var el = doc.getElementsByClassName("salenum");
if(el.length){
obj.price = this.trim(el[0].textContent);
}
var el = doc.getElementById("imagepreview");
if(el){
el = el.getElementsByTagName('img');
if(el.length){
obj.img = el[0].src;
}
}
var pricetxt = obj.price ? " (" + obj.price + ")" : "";
var name = doc.title;
var namelength = obj.price ? 32 : 40;
if(name.length > namelength){
name = name.substring(0,namelength) + "...";
}
title = "BestBuy: " + name + pricetxt;
} else {
return [];
}
break;
default:
return [];
}
result.push(
{
type: "shopping",
title: title,
redirect_url: redirect_url,
preview: this.json.encode(obj)
}
);
}
return result;
},
trim: function (str) {
if(str.trim){
return str.trim();
}
var str = str.replace(/^\s\s*/, ''),
ws = /\s/,
i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
},
json: Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON),
AMAZON: "www.amazon.com",
NEWEGG: "www.newegg.com",
BESTBUY: "www.bestbuy.com",
BUY: "www.buy.com",
WOOT: "www.woot.com",
SHIRTWOOT: "shirt.woot.com",
WINEWOOT: "wine.woot.com",
KIDSWOOT: "kids.woot.com",
SELLOUTWOOT: "sellout.woot.com",
WOOTURL: "http://www.woot.com/",
SELLOUTURL: "http://sellout.woot.com/Default.aspx",
BUYURL: "http://www.buy.com/prod",
BESTBUYURL: "http://www.bestbuy.com/site/olspage.jsp?skuId=",
NEWEGGURL: "http://www.newegg.com/Product/Product.aspx?Item=",
pattern: /^http(?:s*):\/\/(shirt.woot.com|wine.woot.com|kids.woot.com|sellout.woot.com|www.woot.com|www.amazon.com|www.newegg.com|www.buy.com|www.bestbuy.com)/
};